package com.mediacloud.app.newsmodule.fragment.cebian;

import android.util.Log;

import com.mediacloud.app.user.utils.RxUtils;
import com.mediacloud.app.model.utils.BaseDataInvoker;
import com.mediacloud.app.newsmodule.fragment.baoliao.TransUtils;
import com.mediacloud.app.reslib.util.DataInvokeUtil;

import io.reactivex.Observable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * Date:2020/2/10
 * Author:Wy
 */
public class ApiInvoker extends BaseDataInvoker {
    Disposable disposable;

    public void getSecondNav(String navigate_id, int have_own,final SecondNavCallback callBack) {
        Observable<NavigateBean> articleObj = null;

        articleObj = DataInvokeUtil.getZiMeiTiApi().getSecondNav(navigate_id,have_own)
                .compose(TransUtils.fastJSonTransform(NavigateBean.class))
                .compose(RxUtils.<NavigateBean>schedulersTransformer());

        Consumer errorConsumer = new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) {
                if (callBack != null) {
                    callBack.onError();
                }
            }
        };
        if (articleObj != null) {
            Log.e("data", articleObj.toString());
            disposable = articleObj.subscribe(new Consumer<NavigateBean>() {
                @Override
                public void accept(NavigateBean data) {
                    Log.w("APPTAG", data + "");
                    if (callBack != null) {
                        callBack.onSuccess(data);
                    }
                }
            }, errorConsumer);
        }
    }

    public interface SecondNavCallback {
        void onSuccess(NavigateBean data);

        void onError();
    }
    public void getNavigateTag(OnNavigateTagCallback callBack){
        Observable<NavigateTagBean> articleObj = null;

        articleObj = DataInvokeUtil.getZiMeiTiApi().getNavigateTag()
                .compose(TransUtils.fastJSonTransform(NavigateTagBean.class))
                .compose(RxUtils.<NavigateTagBean>schedulersTransformer());

        Consumer errorConsumer = new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) {
                if (callBack != null) {
                    callBack.onError();
                }
            }
        };
        if (articleObj != null) {
            Log.e("data", articleObj.toString());
            disposable = articleObj.subscribe(new Consumer<NavigateTagBean>() {
                @Override
                public void accept(NavigateTagBean data) {
                    Log.w("APPTAG", data + "");
                    if (callBack != null) {
                        callBack.onSuccess(data);
                    }
                }
            }, errorConsumer);
        }
    }

    public interface OnNavigateTagCallback {
        void onSuccess(NavigateTagBean data);

        void onError();
    }


}